﻿using System;
using System.Windows;
using System.Windows.Data;

namespace Wintellect.LiveFx.Cloudboard
{
  public class RoleValueConverter : IValueConverter
  {
    #region IValueConverter Members
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      string parameterString = parameter as string;
      if (parameterString == null)
        return DependencyProperty.UnsetValue;
      if (Role.IsDefined(value.GetType(), value) == false)// || Role.None == (Role)value)
        return DependencyProperty.UnsetValue;
      return value.ToString();
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      string parameterString = parameter as string;
      if (parameterString == null) return DependencyProperty.UnsetValue;
      return Role.Parse(targetType, parameterString);
    }
    #endregion
  }
}
